/** Created by CUIJA on 05-19-2017.*/

var angular = require('angular');
var coreRoutes = require('./routes/core.routes');
var navMenuService = require('./services/menu.service');
var navbarController = require('./components/navbar/navbar.controller');
var navbarComponent = require('./components/navbar/navbar');

var homeController = require('./controller/home.controller');
var loginController = require('./controller/login.controller')

const moduleName = 'core';

angular.module(moduleName, [])
    .config(coreRoutes)
    .factory('navMenuService', navMenuService)
    .component('navbar', navbarComponent)
    .controller('navbarController', navbarController)
    .controller('homeController',homeController)
    .controller('loginController',loginController)
    .run(run);

run.$inject = [
    '$location',
    '$rootScope',
    '$http'
];

function run($location, $rootScope, $http) {
    $rootScope.$on('$locationChangeStart', function (event, current, previous) {
        console.log(JSON.stringify(current));
        var flag = true;
        if(!flag){
            $location.path('/error');
            return;
        }
        console.log("location change to" + JSON.stringify(current));
    });
}

module.exports = moduleName;